package com.bwie.controller;


import com.bwie.bean.Account;
import com.bwie.bean.Ledger;
import com.bwie.service.LedgerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class LedgerController {

    @Resource
    private LedgerService ledgerService;

    @RequestMapping("list.do")
    public String list(
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            String yNumber,
            String jname,
            String kmNo,
            String kmName,
            String sta,
            String ends,
            String jsta,
            String jends,
            String dsta,
            String dends,
            String ysta,
            String yends,
            Model model){

        Map map = new HashMap();
        map.put("yNumber",yNumber);
        map.put("jname",jname);
        map.put("kmNo",kmNo);
        map.put("kmName",kmName);
        map.put("sta",sta);
        map.put("ends",ends);
        map.put("jsta",jsta);
        map.put("jends",jends);
        map.put("dsta",dsta);
        map.put("dends",dends);
        map.put("ysta",ysta);
        map.put("yends",yends);



        PageHelper.startPage(pageNum,3);
        List list=ledgerService.list(map);
        PageInfo pageInfo = new PageInfo(list);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("map",map);
        return "list";
    }

    @RequestMapping("addto.do")
    public String addto(){
        return "add";
    }

    @RequestMapping("listacc.do")
    @ResponseBody
    public Object listacc(){
        List<Account> list=ledgerService.listacc();
        return list;
    }

    @RequestMapping("add.do")
    @ResponseBody
    public Object add(Ledger ledger){
       int i= ledgerService.add(ledger);
       return i;
    }


}






















